<?php

/**
 * Description of index
 *
 * @author Administrator
 */
class Code extends WoniuController {

    public function index() {

        $this->helper('config');
		$query = $this->db->query("select id from caroltc_files");
		$getpage=$_GET["page"]>0?$_GET["page"]:1;
		$pagesize=10;
		$pagestart=($getpage-1)*$pagesize;
		$config1=array(
                "record_count"=>$query->num_rows(),
                "pager_size"=>$pagesize,
                "show_jump"=>true,
                "pager_index"=>$getpage
            );
            $pager_simple=new Pagebreak($config1);
            $pagebreak= $pager_simple->builder_pager();
            $query2 = $this->db->query("select * from caroltc_files order by id desc limit ".$pagestart." , ".$pagesize);
        $this->view("index", array('title' => 'CAROLTC免费资源外链平台','datas'=>$query2->result(),'pagebreak'=>$pagebreak));
    }
	public function show($id=''){
		$this->model('Mycode');
		$datas=$this->model->mycode->getFile($id);
		$this->view("showcode",array('title' => $datas['title'].'-CAROLTC免费资源外链平台','datas'=>$datas));
	}
		public function showfiles(){
		$query = $this->db->query("select * from caroltc_files where files !='' order by id desc");
        $this->view("showfiles", array('title' => '附件管理-CAROLTC免费资源外链平台','datas'=>$query->result()));
	}
	public function addcode(){
		$this->view("addcode",array('title' => '添加CODE-CAROLTC免费资源外链平台'));
	}
	public function adddeal(){
		$files = $_SESSION['UPLOADNAME'];
		$data = array(
               'title' => $_POST['title'],
               'password' =>sha1($_POST['password']),
               'contents' => $_POST['contents'],
			   'files' => $files
            );
		$msg='';
		if($_SESSION['UPLOADST']=='N' || $_SESSION['UPLOADNAME']=='')
		{
			$msg.='上传失败，请重新上传后提交！';
		}else{
		if($_POST['title']!=""){
		if($this->db->insert('files', $data)){
			$msg.='保存成功<br/>';
			$_SESSION['UPLOADNAME']='';
			//$upload=new Fileupload();
			//$msg.=$upload->upload();
			} else{
			$msg.='保存失败，请检查！<br/>';
				}
		}else{
			$msg.='标题不能为空，请检查！<br/>';
			}
		}
		$this->view("deal",array('msg'=>$msg,'title' => '处理结果-CAROLTC免费资源外链平台'));
	}
	public function qiniu(){
		
	}
}
